import { AddMobileContactData } from '@/utils/common-api.js'

export default {
  data() {
    return {
      keyword: '',
      searchkey: '', //搜索条件
      // 搜索框1
      sousuo: '',
      shape: 'round',
      clearabled: true,
      showAction: true,
      inputAlign: 'left',
      addresslist: [],
      Ssaddresslist: [],
      indexlist: [],
      Xsyc: true,
      storelist: [],
      type: 0, //发布车源117
      typeName: '', //发布车源name
      pageindex: 1, //
      pagecont: 0, //总条数
    }
  },
  // 上拉加载分页scroll-view到底部加载更多
  onReachBottom() {
    this.pageindex = ++this.pageindex
    this.GetStoreDataList()
    var pagezs = (this.pagecont + 10 - 1) / 10
    if (this.pageindex >= pagezs) {
      this.status = 'nomore'
      return
    }
    this.status = 'loadmore'
    setTimeout(() => {
      if (this.pageindex >= pagezs) {
        this.status = 'nomore'
      } else {
        this.status = 'loading'
      }
    }, 1000)
  },
  onLoad(typex) {
    this.type = typex.type
    if (this.type === '117') {
      this.typeName = '车源'
      // uni.setNavigationBarTitle({
      //   title: '车源'
      // })
    }
    this.GetStoreDataList()
  },
  methods: {
    // 店铺
    async GetStoreDataList() {
      try {
        let data = {
          PageIndex: this.pageindex, //当前页码
          PageSize: 10, //每页条数
        }
        const res = await this.$api.carSource.GetStoreDataList(data)
        this.pagecont = res.data.total
        if (res.data.list === 0 && this.pageindex === 1) {
          this.storelist = []
          return false
        }
        if (this.pageindex === 1) {
          this.storelist = res.data.list
        } else if (this.pageindex > 1) {
          this.storelist = this.storelist.concat(res.data.list)
        }
      } catch (err) {
        console.log(err)
      }
    },
    //查看我的寻车
    chakanwxc() {
      //车源管理
      if (this.type === '117') {
        uni.redirectTo({
          url: '/pages_carSource/managementOptions/managementOptions',
        })
      } else {
        uni.navigateTo({
          url: '/pages_findCar/iFoundTheCar/iFoundTheCar',
        })
      }
    },
    // 拨打电话
    phoneclick(phone) {
      uni.makePhoneCall({
        phoneNumber: phone,
      })
    },
    //联系商家
    contactSeller(data) {
      AddMobileContactData(this.$store.state.userInfoDetail.store.storeId)
      this.$store.commit('news/createConversationActive', {
        user: data.store_Name, //店铺名称
        img: data.store_Topimg, //店铺头像
        lastTime: '', //
        userId: data.id, //店铺id
        conversationID: 'C2C' + data.id,
      })
      uni.navigateTo({
        url: `/pages_news/contactSeller/contactSeller?user=${data.store_Name}&type=1`,
      })
    },
  },
}
